﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using Microsoft.Practices.Unity;
using RG.Common.WPF;

namespace RG.Common.WPF.BaseSelector
{
    public abstract class Helper<TSelf> : IHelper
        where TSelf : class, IEditableObject, ILoadFrame
    {
        [Dependency]
        public WorkplaceWorker Worker { get; set; }

        [Dependency]
        public IUnityContainer Cfg { get; set; }

        public abstract List<INamed> List(string name);

        //public abstract ILoadFrame GetVM();

        public INamed Search(string name)
        {
            var vm = Cfg.Resolve<TSelf>();
            vm.Load(()=>List(name));
            if (!Worker.Workplace.ShowEditableDialog(vm, "Выберите счетчик проходимости")) return null;
            return vm.SelectedItem;
        }

        public INamed Overview()
        {
            return Search(null);
        }
    }
}